// ==================================================================
// 描 述：
// 作 者：王征:D
// 创建时间：2019/06/11 20:15:07
// ==============================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using Yunchang;
using Table.DataModel;

namespace AutoChess
{
    public class ACChessInfoWindow : MonoBehaviour
    {
        public Text heroName;
        public Text heroType;
        public Text heroTargetType;
        public Text[] topPropValues;

        public SkillIntroductionItem skill1;
        public SkillIntroductionItem skill2;
        public SkillIntroductionItem skill3;
        public SkillIntroductionItem skill4;

        public GroupSpriteKit[] GroupSprites; // 俩
        public Text[] ChessNumTxt; // 6最多
        public Text[] BuffTxt;

        public UI.AutoScrollContent[] textScrolls;

        public void SetData(int chessId)
        {
            var tableChess = Table.Blo.AutoChessBlo.GetChessTable(chessId);
            var tableChessHero = Table.Blo.AutoChessBlo.GetChessHero(tableChess.heroId);
            var tableHero = Table.Blo.TableHeroBlo.GetTableHero(tableChess.heroId);

            heroName.text = TableTextBlo.TransferText(tableHero.heroName);
            heroType.text = TableTextBlo.TransferText(tableChessHero.heroStyle);
            heroTargetType.text = TableTextBlo.TransferText(tableHero.heroAttackTarget);

            skill1.gameObject.SetActive(tableChess.skill1 != 0);
            skill2.gameObject.SetActive(tableChess.skill2 != 0);
            skill3.gameObject.SetActive(tableChess.skill3 != 0);
            skill4.gameObject.SetActive(tableChess.ultimateSkill != 0);
            if (tableChess.skill1 != 0)
            {
                skill1.InitSkillDes(tableChess.skill1);
            }
            if (tableChess.skill2 != 0)
            {
                skill2.InitSkillDes(tableChess.skill2);
            }
            if (tableChess.skill3 != 0)
            {
                skill3.InitSkillDes(tableChess.skill3);
            }
            if (tableChess.ultimateSkill != 0)
            {
                skill4.InitSkillDes(tableChess.ultimateSkill);
            }

            topPropValues[0].text = ((int)tableChess.hp).ToString();
            topPropValues[1].text = ((int)tableChess.atk).ToString();
            topPropValues[2].text = ((int)tableChess.def).ToString();
            topPropValues[3].text = ((int)tableChess.speed).ToString();

            var str_group = tableChessHero.acHeroGroups.Split(';');

            // 最多俩buff
            for (int i = 0; i < 2; i++)
            {
                if (i >= str_group.Length)
                {
                    GroupSprites[i].transform.parent.gameObject.SetActive(false);
                    break;
                }

                GroupSprites[i].transform.parent.gameObject.SetActive(true);
                int acHeroGroup = int.Parse(str_group[i]);
                var allBuffs = Table.Blo.AutoChessBlo.GetGroupBuffsByGroupId(acHeroGroup);
                var acGroup = Table.Blo.AutoChessBlo.GetGroup(acHeroGroup);
                var heroGroup = Table.Blo.TableHeroBlo.GetTableHeroGroup(acHeroGroup);

                int textIndex = -1;
                int lastHeroNum = 0;
                for (int i0 = 0; i0 < allBuffs.Count; i0++)
                {
                    var buff = allBuffs[i0];
                    if (buff.needHeroNum == lastHeroNum)
                    {
                        BuffTxt[i * 3 + textIndex].text += " " + buff.desc;
                    }
                    else
                    {
                        ++textIndex;
                        lastHeroNum = buff.needHeroNum;

                        ChessNumTxt[i * 3 + textIndex].transform.parent.gameObject.SetActive(true);

                        BuffTxt[i * 3 + textIndex].text = buff.desc;
                        ChessNumTxt[i * 3 + textIndex].text = buff.needHeroNum.ToString();
                        // 这里直接显示隐藏就完了
                        //HeadSprites[textIndex].
                    }
                }

                ++textIndex;
                for (; textIndex < 3; textIndex++)
                {
                    ChessNumTxt[i * 3 + textIndex].transform.parent.gameObject.SetActive(false);
                }

                GroupSprites[i].SetSpriteName(acGroup.altasName);
            }

            for (int i = 0; i < BuffTxt.Length; i++)
            {
                BuffTxt[i].transform.GetComponent<ContentSizeFitter>().SetLayoutHorizontal();
            }

            for (int i = 0; i < textScrolls.Length; i++)
            {
                textScrolls[i].ResetToBeginning();
            }

            
        }
    }
}
